package cn.kinoko.controller.manga;

import cn.kinoko.common.aspect.annotation.Lock;
import cn.kinoko.common.base.model.BaseController;
import cn.kinoko.common.base.model.Result;
import cn.kinoko.common.constant.CacheKeyConstant;
import cn.kinoko.model.manga.req.MarkCommentReq;
import cn.kinoko.model.manga.req.MarkReq;
import cn.kinoko.model.manga.vo.MarkVO;
import cn.kinoko.service.manga.MangaService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author kinoko
 */
@RestController
@RequestMapping("/manga/edit")
public class MangaEditController extends BaseController {

    @Resource
    private MangaService mangaService;

    @GetMapping("/markList")
    public Result<List<MarkVO>> markList(@RequestParam Long epRid) {
        return success(mangaService.markList(epRid));
    }

    @Lock(key = CacheKeyConstant.LOCK_RAW_EP_ON_MARK, params = "#req.epRid", expire = 5, errorDesc = "操作太频繁咯，让服务器君喘喘")
    @PostMapping("/saveMark")
    public Result<Object> save(@RequestBody MarkReq req) {
        return success(mangaService.saveMark(req));
    }

    @PostMapping("/comment")
    public Result<Object> comment(@RequestBody @Valid MarkCommentReq req) {
        return success(mangaService.comment(req));
    }

    @GetMapping("/undoComment")
    public Result<Object> undoComment(@RequestParam Long id) {
        return success(mangaService.undoComment(id));
    }

    @GetMapping("/queryComment")
    public Result<Object> queryComment(@RequestParam Long markId) {
        return success(mangaService.queryComment(markId));
    }
}
